
<?php
function edit_member(){
		if($this->session->userdata('is_login')){
			$post = $this->input->post('submit');

			if($post){
				$this->load->model('member');

				$this->load->library('form_validation');

				$this->form_validation->set_rules('nama_lengkap', 'NAMA LENGKAP', 'required');
				$this->form_validation->set_rules('pwd', 'Password', 'required');
				$this->form_validation->set_rules('nama_panggilan', 'NAMA PANGGILAN', 'required');
				$this->form_validation->set_rules('no_telp', 'NOMOR TELEPON', 'required');
				$this->form_validation->set_rules('email', 'EMAIL', 'required');
				$this->form_validation->set_rules('alamat', 'ALAMAT', 'required');

				if ($this->form_validation->run() == FALSE){
					$data ['error'] = validation_errors ();
				} else {

					$NIM = $this->session->userdata('NIM');
					$pwd = $this ->input->post('pwd');
					$nama_lengkap = $this ->input->post('nama_lengkap');
					$telp = $this ->input->post('no_telp');
					$email = $this ->input->post('email');
					$alamat = $this ->input->post('alamat');


					$ubah = $this->member->updateMember($NIM, $nama_lengkap, $nama_lengkap, $alamat, $telp, $email, $pwd);

					if($ubah){
							$NIM = $this ->input->post('NIM');
							$userData = $this->member->getDetailMember($NIM);
					
					
							if(!empty($userData)){
								$sessionData['id'] = $userData['id_member'];
								$sessionData['nama'] = $userData['nama'];
								$sessionData['NIM'] = $userData['nim'];
								$sessionData['password'] = $userData['password'];
								$sessionData['divisi'] = $this->member->getDivisi($userData['id_divisi']);
								$sessionData['photo'] = $this->member->getPhoto($userData['nim']);
								$sessionData['email'] = $userData['email'];
								$sessionData['telp'] = $userData['telp'];
								$sessionData['alamat'] = $userData['alamat'];
								$this->session->set_userdata($sessionData);
								//echo "berhasil";
								redirect('web/member');

							}else{
								$data['error']   = $this->session->flashdata('error');
							}

			
					}else{
							$data['error']   = "Error Mengubah Data";
					}

				$this->load->model('member');

				$data['info'] = $this->web_model->getAllInfo();
				$data['materi_desktop'] = $this->web_model->getElearningDesktop();
				$data['materi_web'] = $this->web_model->getElearningWeb();
				$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
				$data['materi_hardware'] = $this->web_model->getElearningHardware();
				
				$data['materi'] = $this->web_model->getElearning();
				$data['divisi'] = $this->web_model->getDivisi();
				
				$this->load->view('web/header', $data);
				$this->load->view('web/left_sidebar', $data);
				$this->load->view('member/editmember', $data);
				$this->load->view('web/footer');

		} else {
			redirect('web/restricted');
		}
	}
?>